package com.example.positioning.service;

import com.example.positioning.mqtt.EmqClient;
import com.example.positioning.mqtt.MqttProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

@Service
public class Chushihua {
    public String[]pub= new String[]{
            "rtk/[device_id]/mxt/downlink",
            "rtk/rtcm",
            "dwm/node/[device_id]/downlink/config"
    };
    public String[]sub=new String[]{
            "rtk/[device_id]/mxt/uplink",
            "rtk/[device_id]/nmea",
            "dwm/node/[device_id]/uplink/status",
            "dwm/node/[device_id]/uplink/location",
            "dwm/node/[device_id]/uplink/config",
            "test"
    };
    private String[]id=new String[]{"0e2d"};
    @Autowired
    private EmqClient emqClient;
    @Autowired
    private MqttProperties mqttProperties;
    @PostConstruct
    public void init(){
        emqClient.connect(
                mqttProperties.getUsername(),
                mqttProperties.getPassword());
        SubAll();
    }
    public void duiying(){
    }
    public void SubAll(){
        for (String value : id) {
            for (String s : sub) {
                emqClient.substribe(s.replace("[device_id]", value)
                        , 1);
                System.out.println(s.replace("[device_id]", value));
            }
        }
    }
}
